<%-- 
    Document   : readShoppingCart
    Created on : 1 juin 2012, 21:33:50
    Author     : isen
--%>

<%@page import="persistence.PersistenceInterface"%>
<%@page import="persistence.PersistenceFactory"%>
<%@page import="persistence.PersistenceImplementation"%>
<%@page import="model.CartContent"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Content of you shoppingcart</title>
    </head>
    <body>
    <center>
        <h1>Products you have in your ShoppingCart</h1>
		<% String clientname = (String) request.getSession().getAttribute("user");
		
		try{         
			int cartid = PersistenceImplementation.getJDBCPersistenceManager().getCurrentCartId(clientname);
			if (cartid != 0) {
                            
                            ArrayList<CartContent> cartContents = PersistenceImplementation.getJDBCPersistenceManager().getCartContents(cartid);
                            if (!cartContents.isEmpty()){ %>
			<table>
	            <tr><td>Nombre</td><td>Precio</td></tr>
	            <% for (int i=0; i<cartContents.size();i++) {%>
	            <tr>
	                <td><%= cartContents.get(i).getProductname()%></td>
	                <td><%= cartContents.get(i).getQuantity()%></td>
	            </tr>
	            <% }%>
	        </table>
			<% }else { %>
				<p>No se han encontrado productos en el carrito</p>
            <% } 
            }else { %>
				<p>Your shoppingcart is empty</p>
          <%  }
		}catch(Exception ex){ %>
                <% ex.printStackTrace ();%>
			<p>Sorry, we can not show you the content of your cart</p>
		<% } %>

    </center>
                                
            <%@include file="/WEB-INF/include/menuClient.jsp" %>
</body>
</html>
